<template>
  <div>
    <!-- 搜索 -->
    <!-- 索赔申请 -->
    <TopFilter ref="TopFilterss" :list="topFilterInit" :cols="3" :collapse="collapse"  labelWidth="120" @filterChange="changeHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      selectionType="single"
      :columns="columns"
      :params="fetchParams"
      :dataSource="dataList"
      :fetchapi="fetchApi"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
    >
    </FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <multiuse-button @click="closeDialog">关 闭</multiuse-button>
      <multiuse-button type="primary" :click="saveDialog.bind()">添加</multiuse-button>
    </div>
    <BaseDialog :visible.sync="ModelVisible" :title="'车型选择'" destroyOnClose width="850px" :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <ModelVehicle @close="modelClose" @save="modelSave"></ModelVehicle>
    </BaseDialog>

  </div>
</template>
<script>
  import {getCaseListForQa} from '@/api/claim/factory/QualityInformationManagement_OEM/QualityInformationExamine/index';
  import { exportExcelFile } from '@/utils/index';
  import { getPartType } from '@/api/dictionary/index';
  import ModelVehicle from '@/pages/claimDemage/tools/ModelVehicle.vue';
  import { dictionary } from '@/utils/dictMixin';
  export default {
    props: ['partCode'],
     mixins: [dictionary],
    components: {
      ModelVehicle
    },
    data() {
      return {
        dataList: [],
        visible: false,
        visibleDrawer: false,
        collapse: false,
        infoId: null,
        topFilterInit: this.topFilterInitFun(),
        flterValue: {}, //参数
        fetchApi:getCaseListForQa,
        columns: this.creatHeader(),
        fetchParams: {}, //ipa 接口
        selectedRows: [], //选中经销商
        dialogTitle: '选择车辆',
        visibleAdd: false,
        visibleEdit:false,
        rowData:{},
        ModelVisible:false,
      };
    },
    created() {
      this.chuqi();
    },
    methods: {
      //搜索数据
      topFilterInitFun() {
        return [
          { type: 'INPUT', label: '案例编号', fieldName: 'caseNo', placeholder: '请输入', initialValue: '' },
          { type: 'INPUT', label: '案例主题', fieldName: 'caseTitle', placeholder: '请输入', initialValue: '' },
          {
            type: 'INPUT',
            label: '车型名称',
            fieldName: 'modelName',
            placeholder: '请输入数量...',
            unitRender: (p) => {
              return (
                <div>
                <multiuse-button icon="el-icon-search" onClick={() => this.selectModleCode()} />
              </div>
            );
            },
          },
          {
            type: 'SELECT',
            label: '故障等级',
            fieldName: 'caseLevel',
            itemList: [],
          },

          { type: 'RANGE_DATE', label: '案例创建日期', fieldName: 'beginCreatedAt|endCreatedAt', placeholder: '请输入', initialValue: '' },
          { type: 'INPUT', label: '故障现象代码', fieldName: 'faultCode', placeholder: '请输入', initialValue: '' },
          { type: 'INPUT', label: '配件代码', fieldName: 'partCode', placeholder: '请输入', initialValue: '' },
          { type: 'INPUT', label: '配件名称', fieldName: 'partName', placeholder: '请输入', initialValue: '' },
        ];
      },
      //搜索获取数据
      changeHandle(val) {
        this.fetchParams=Object.assign({},val);
        console.log(val);
      },
      //table表头和数据源
      creatHeader() {
        return [
          {
            title: '序号',
            dataIndex: 'index',
            width: 80,
            sorter: true,
            render: props => {
              return <span>{props.row.index + 1}</span>;
            }
          },
          { title: '案例编号', dataIndex: 'caseNo', sorter: true },
          { title: '案例主题', dataIndex: 'caseTitle', sorter: true },
          { title: '车型', dataIndex: 'modelName', sorter: true },
          { title: '配件代码', dataIndex: 'partCode', sorter: true },
          { title: '配件名称', dataIndex: 'partName', sorter: true },
          { title: '故障现象代码', dataIndex: 'faultCode', sorter: true },
          { title: '故障现象名称', dataIndex: 'faultName', sorter: true },
          { title: '故障等级', dataIndex: 'caseLevelStr', sorter: true },
          { title: '故障次数', dataIndex: 'faultTimes', sorter: true },
          { title: '质量部故障等级', dataIndex: 'resultLevel', sorter: true,
            filterItems: this.createDictList('5563'),
            render: props => {    //编码转汉字
              return <span>{this.createDictText(props.row.resultLevel, '5563')}</span>;
            } },
          { title: '创建人', dataIndex: 'createdBy', sorter: true },
          { title: '创建时间', dataIndex: 'createdAt', sorter: true },
        ];
      },
      async chuqi(){
        console.log("进来了")
        const res3 = await getPartType({ type: 5563 });
        if (res3.resultCode == 200) {
          this.topFilterInit.find((x) => x.fieldName == 'caseLevel').itemList = res3.data.map((y) => ({
            text: y.codeCnDesc,
            value: y.codeId,
          }));
        }
      },
      //选中
      selectChange(rows) {
        this.selectedRows = rows;
        console.log("********************",this.selectedRows);
      },
      saveDialog() {
        // console.log("********************",this.partCode);
        // if(this.partCode !=this.selectedRows[0].partCode){
        //   this.$confirm('所选案例与质量报告单主损件不一致，上报会覆盖案例主损件，是否确定?', '提示', {
        //     confirmButtonText: '确定',
        //     cancelButtonText: '取消',
        //     type: 'warning'
        //   })
        //     .then(async() => {
        //       this.$emit('save', this.selectedRows);
        //     })
        //     .catch(() => {});
        // }
        this.$emit('save', this.selectedRows);
      },
      close() {
        this.visible = false;
      },
      chooseOrderNo() {
        this.visible = true;
      },
      save(obj) {
        this.topFilterInit.find(x => x.fieldName == 'modelCode').initialValue = obj[0].modelCode;
        this.visible = false;
      },
      //取消操作
      closeDialog() {
        this.$emit('close', { visible: false, data: this.selectedRows, type: 'close' });
      },
      modelSave(obj) {
        this.topFilterInit.find(x => x.fieldName == 'modelName').initialValue = obj[0].modelName;
        this.ModelVisible = false;
      },
      modelClose(){
        this.ModelVisible = false;
      },
      selectModleCode(){
        this.ModelVisible = true;
      },
    }

    // mounted() {
    //   this.BaseTable = this.$refs.listModal.$refs.pageTable;
    // }
  };
</script>

<style lang="less" scoped></style>
